var commonMixin = {
    methods: {
        //存储cookie (强制根目录)
        setCookie(name, value) {
            var _this = this;
            var Days = 30;
            var exp = new Date();
            exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
            document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
        },
        //得到cookie
        getCookie(name) {
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            if (arr = document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return null;
        },
        //删除cookie
        removeCookie(name) {
            var exp = new Date();
            exp.setTime(exp.getTime() - 1);
            //删除当前目录下的cookie
            document.cookie = name + "=;expires=" + exp.toGMTString();
            //删除根目录下的cookie
            document.cookie = name + "=;expires=" + exp.toGMTString() + ";path=/";
        },
        //获取url参数
        getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2]);
            } else {
                var strHash = window.location.hash;

                if (strHash &&
                    strHash.length > 0 &&
                    strHash.indexOf("?") > -1) {
                    r = strHash.substr(strHash.indexOf("?") + 1).match(reg);
                }
                if (r != null) {
                    return unescape(r[2]);
                }
            }
            return null;
        },
        //更新url参数
        updateQueryStringParameter(uri, key, value) {
            var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
            var separator = uri.indexOf('?') !== -1 ? "&" : "?";
            if (uri.match(re)) {
                return uri.replace(re, '$1' + key + "=" + value + '$2');
            } else {
                return uri + separator + key + "=" + value;
            }
        },
        openExternal(link){
            this.$electron.shell.openExternal(link)
        }

    }
}
export {
    commonMixin
};